什麼是 GitLab CI Runner,我們在 CI 跑的動作是 CI Job,而跑這個 Job 的 worker 就是 runner。通常大公司內都會有多個多個 runner 供部署使用。如果 job 數量遠大於 runner,Job 就會處於 pending 的狀況。Runner 的運作模式是會不斷地向 Gitlab 發出 requests 確認有沒有需要執行的 runner。如果有 Job 且 Job 的 tag 跟 runner 符合,就可以執行。
參考官方文檔,因為我只是自己的環境玩玩,我想採用最簡單的:Install GitLab Runner on macOS
下載 binary(Apple Silicon-based systems)
sudo curl --output /usr/local/bin/gitlab-runner "https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-darwin-arm64"
給 permission 讓他可以執行
sudo chmod +x /usr/local/bin/gitlab-runner
作為 runners 的 user
gitlab-runner register --url https://gitlab.com --token glrt-xxxxx
gitlab-runner register --url https://gitlab.com --token glrt-xxx
Runtime platform arch=arm64 os=darwin pid=29503 revision=071ba93d version=17.3.0
WARNING: Running in user-mode.
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Created missing unique system ID system_id=s_844cd5e23355
Enter the GitLab instance URL (for example, https://gitlab.com/):
[https://gitlab.com]:
Verifying runner... is valid runner=os1MWSbF6
Enter a name for the runner. This is stored only in the local config.toml file:
[Alvinlin.local]:
Enter an executor: custom, parallels, docker, docker-windows, docker+machine, kubernetes, instance, shell, ssh, virtualbox, docker-autoscaler:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/Users/alvinlin/.gitlab-runner/config.toml"
試著跑以下指令,會看到程序持續進行中
gitlab-runner run
$ gitlab-runner run
Runtime platform arch=arm64 os=darwin pid=29585 revision=071ba93d version=17.3.0
Starting multi-runner from /Users/alvinlin/.gitlab-runner/config.toml... builds=0 max_builds=0
WARNING: Running in user-mode.
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Configuration loaded builds=0 max_builds=1
listen_address not defined, metrics & debug endpoints disabled builds=0 max_builds=1
[session_server].listen_address not defined, session endpoints disabled builds=0 max_builds=1
Initializing executor providers builds=0 max_builds=1